package com.hotau.common;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hotau.HotauActivity;
import com.hotau.R;
import com.hotau.member.LoginFragment;

/**
 * 消息提示
 * @author liujia (liujia9234@126.com)
 * @data 2011-12-9
 * @version 1.0
 * <ul>
 * 		<li>1.0 创建</li>
 * </ul>
 */
public class MessagePromptFragment extends Fragment implements OnClickListener {

	public static final String TAG = "LostPwdResultFragment";
	private boolean success = false;
	private String message = "";
	
	private ImageView common_message_iv_pic = null;
	private TextView  common_message_tv_text = null;
	private Button common_message_btn_back = null;
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		initAllWidget();
		initAllEvent();
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		this.success = getArguments().getBoolean("success");
		this.message = getArguments().getString("message");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.common_message, container,false);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.common_message_pwdresult_btn_back:
			HotauActivity csmbpActivity = (HotauActivity) getActivity();
			if(success){
				csmbpActivity.pushFragment("登录", new LoginFragment());
			}else{
//				csmbpActivity.onBackPressed();
				csmbpActivity.popFragment();
			}
			break;
		default:
			break;
		}
	}
	
	/**
	 * 初始化所有控件
	 */
	public void initAllWidget() {
		common_message_iv_pic = (ImageView) getActivity().findViewById(R.id.common_message_pwdresult_iv_pic);
		common_message_tv_text = (TextView) getActivity().findViewById(R.id.common_message_pwdresult_tv_text);
		common_message_btn_back = (Button) getActivity().findViewById(R.id.common_message_pwdresult_btn_back);
		
		if(success){
			common_message_iv_pic.setImageResource(R.drawable.checkbox_on_background_focus_yellow);
			common_message_tv_text.setText(message);
			common_message_btn_back.setText("登录");
		}else{
			common_message_iv_pic.setImageResource(R.drawable.checkbox_off_background_focus_yellow);
			common_message_tv_text.setText(message);
			common_message_btn_back.setText("返回上一页");
		}
		
	}
	
	/**
	 * 初始化所有事件
	 */
	public void initAllEvent() {
		common_message_btn_back.setOnClickListener(this);
	}

}
